package mashuaiproject.mashuaiproject.mapper;

import mashuaiproject.mashuaiproject.model.Notification;
import mashuaiproject.mashuaiproject.model.Users;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.List;

@Component
public interface NotificationMapper {

    @Insert("insert into notification(notifier,receiver,type,status,gmt_create,quesion_id,content,comment_id)values(" +
            "#{notifier},#{receiver},#{type},#{status},#{gmt_create},#{quesion_id},#{content},#{comment_id})")
    void insert(Notification notification);

    @Select("select *from notification where receiver=#{receiver} order by status asc limit #{page},#{size}")
    List<Notification> selectCurrentNotified(@Param("receiver") Integer id,@Param("page") Integer page,@Param("size")Integer size);

    @Select("select *from users where id=#{notifier}")
    Users selectNotifiedUsers1(@Param("notifier") Integer notifier);

    @Select("select title from quesions where id=#{quesion_id}")
    String slectReciverQuesion1(@Param("quesion_id") Integer quesion_id);

    @Select("select content from comment where id=#{comment_id}")
    String selectReciverComment1(@Param("comment_id") Integer comment_id);

    @Select("select  count(1) from notification where receiver=#{id} and status=1")
    Integer selectNoReadCount(@Param("id") Integer id);

    @Update("update notification set status=2 where id=#{notifi_id}")
    int updateStatus(@Param("notifi_id") int notifi_id);

    @Select("select  count(1) from notification where receiver=#{id}")
    Integer sleectCount(Integer id);
}
